<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <style>
    .talign {
      text-align: center;
    }
    ul {
      height: 800px;
    }
  </style>
  <body>
    <div id="app">
      <!-- 上拉加载分页
      van-list
        v-model:是否处于加载中,true:正处于加载中,false:当次(当前页)加载完成,上拉过程中自动变成true,离底部小于300px就会触发
        finished:是否加载完成,(是否到了最后一页)  false:加载没有完成 true加载已完成(停止加载(不再执行load方法))
        finished-text:如果到了最后一面.最下面显示的文本内容
        @load="上拉过程中触发的方法"
    -->
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多数据了"
        @load="load"
      >
        <ul>
          <li class="talign" v-for="(item, index) in arr" :key="index">
            {{item}}
          </li>
        </ul>
      </van-list>
    </div>
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/vant@2.10/lib/index.css"
    />

    <!-- 引入 Vue 和 Vant 的 JS 文件 -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6/dist/vue.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vant@2.10/lib/vant.min.js"></script>
    <script>
      new Vue({
        el: '#app',
        data: {
          currentPage: 0,
          pageSize: 2,
          total: 20,
          loading: false,
          finished: false,
          arr: []
        },
        methods: {
          load () {
            this.currentPage++
            setTimeout(() => {
              // [二个随机数]
              // this.arr = [1, 2]
              // this.arr.push(...[1, 2])
              this.arr.push(Math.random() * 999)
              this.arr.push(Math.random() * 999)
              this.loading = false
              // 判断是否是最后一面,是否加载完成
              if (this.total <= this.arr.length) {
                this.finished = true
              }
            }, 1000)
            window.console.log(1)
          }
        }
      })
    </script>
  </body>
</html>
